home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / Universal Headers 2.0.1f / OSUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-22  |  13.8 KB  |  566 lines  |  [TEXT/MMCC]

  1. /*
  2.      File:        OSUtils.h
  3.  
  4.      Contains:    OS Utilities Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.0 in “MPW Latest” on ETO #17
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. */
  19.  
  20. #ifndef __OSUTILS__
  21. #define __OSUTILS__
  22.  
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. /*    #include <ConditionalMacros.h>                                */
  28.  
  29. #ifndef __MIXEDMODE__
  30. #include <MixedMode.h>
  31. #endif
  32.  
  33. #ifndef __MEMORY__
  34. #include <Memory.h>
  35. #endif
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40.  
  41. #if PRAGMA_ALIGN_SUPPORTED
  42. #pragma options align=mac68k
  43. #endif
  44.  
  45. #if PRAGMA_IMPORT_SUPPORTED
  46. #pragma import on
  47. #endif
  48.  
  49.  
  50. enum {
  51.     useFree                        = 0,
  52.     useATalk                    = 1,
  53.     useAsync                    = 2,
  54.     useExtClk                    = 3,                            /*Externally clocked*/
  55.     useMIDI                        = 4,
  56. /* Environs Equates */
  57.     curSysEnvVers                = 2,                            /*Updated to equal latest SysEnvirons version*/
  58. /* Machine Types */
  59.     envMac                        = -1,
  60.     envXL                        = -2,
  61.     envMachUnknown                = 0,
  62.     env512KE                    = 1,
  63.     envMacPlus                    = 2,
  64.     envSE                        = 3,
  65.     envMacII                    = 4,
  66.     envMacIIx                    = 5,
  67.     envMacIIcx                    = 6,
  68.     envSE30                        = 7,
  69.     envPortable                    = 8,
  70.     envMacIIci                    = 9,
  71.     envMacIIfx                    = 11,
  72. /* CPU types */
  73.     envCPUUnknown                = 0
  74. };
  75.  
  76. enum {
  77.     env68000                    = 1,
  78.     env68010                    = 2,
  79.     env68020                    = 3,
  80.     env68030                    = 4,
  81.     env68040                    = 5,
  82. /* Keyboard types */
  83.     envUnknownKbd                = 0,
  84.     envMacKbd                    = 1,
  85.     envMacAndPad                = 2,
  86.     envMacPlusKbd                = 3,
  87.     envAExtendKbd                = 4,
  88.     envStandADBKbd                = 5,
  89.     envPrtblADBKbd                = 6,
  90.     envPrtblISOKbd                = 7,
  91.     envStdISOADBKbd                = 8,
  92.     envExtISOADBKbd                = 9,
  93.     false32b                    = 0,                            /*24 bit addressing error*/
  94.     true32b                        = 1,                            /*32 bit addressing error*/
  95. /* result types for RelString Call */
  96.     sortsBefore                    = -1,                            /*first string < second string*/
  97.     sortsEqual                    = 0,                            /*first string = second string*/
  98.     sortsAfter                    = 1                                /*first string > second string*/
  99. };
  100.  
  101. enum {
  102. /* Toggle results */
  103.     toggleUndefined                = 0,
  104.     toggleOK                    = 1,
  105.     toggleBadField                = 2,
  106.     toggleBadDelta                = 3,
  107.     toggleBadChar                = 4,
  108.     toggleUnknown                = 5,
  109.     toggleBadNum                = 6,
  110.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  111.     toggleErr3                    = 7,
  112.     toggleErr4                    = 8,
  113.     toggleErr5                    = 9,
  114. /* Date equates */
  115.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  116.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  117.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  118.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  119.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  120.     validDateFields                = -1,
  121.     maxDateField                = 10,
  122.     eraMask                        = 0x0001,
  123.     yearMask                    = 0x0002,
  124.     monthMask                    = 0x0004,
  125.     dayMask                        = 0x0008,
  126.     hourMask                    = 0x0010,
  127.     minuteMask                    = 0x0020,
  128.     secondMask                    = 0x0040,
  129.     dayOfWeekMask                = 0x0080,
  130.     dayOfYearMask                = 0x0100,
  131.     weekOfYearMask                = 0x0200,
  132.     pmMask                        = 0x0400,
  133.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  134. };
  135.  
  136. enum {
  137.     eraField,
  138.     yearField,
  139.     monthField,
  140.     dayField,
  141.     hourField,
  142.     minuteField,
  143.     secondField,
  144.     dayOfWeekField,
  145.     dayOfYearField,
  146.     weekOfYearField,
  147.     pmField,
  148.     res1Field,
  149.     res2Field,
  150.     res3Field
  151. };
  152.  
  153. typedef SignedByte LongDateField;
  154.  
  155.  
  156. enum {
  157.     dummyType,
  158.     vType,
  159.     ioQType,
  160.     drvQType,
  161.     evType,
  162.     fsQType,
  163.     sIQType,
  164.     dtQType,
  165.     nmType
  166. };
  167.  
  168. typedef SignedByte QTypes;
  169.  
  170.  
  171. enum {
  172.     OSTrap,
  173.     ToolTrap
  174. };
  175.  
  176. typedef SignedByte TrapType;
  177.  
  178. struct SysParmType {
  179.     UInt8                            valid;
  180.     UInt8                            aTalkA;
  181.     UInt8                            aTalkB;
  182.     UInt8                            config;
  183.     short                            portA;
  184.     short                            portB;
  185.     long                            alarm;
  186.     short                            font;
  187.     short                            kbdPrint;
  188.     short                            volClik;
  189.     short                            misc;
  190. };
  191. typedef struct SysParmType SysParmType, *SysPPtr;
  192.  
  193. typedef struct QElem QElem;
  194.  
  195. typedef QElem *QElemPtr;
  196.  
  197. struct QElem {
  198.     QElemPtr                        qLink;
  199.     short                            qType;
  200.     short                            qData[1];
  201. };
  202. typedef struct QHdr QHdr;
  203.  
  204. typedef QHdr *QHdrPtr;
  205.  
  206. struct QHdr {
  207.     short                            qFlags;
  208.     QElemPtr                        qHead;
  209.     QElemPtr                        qTail;
  210. };
  211. /*
  212.         DeferredTaskProcPtr uses register based parameters on the 68k and cannot
  213.         be written in or called from a high-level language without the help of
  214.         mixed mode or assembly glue.
  215.  
  216.             typedef pascal void (*DeferredTaskProcPtr)(long dtParam);
  217.  
  218.         In:
  219.          => dtParam         A1.L
  220. */
  221.  
  222. #if GENERATINGCFM
  223. typedef UniversalProcPtr DeferredTaskUPP;
  224. #else
  225. typedef Register68kProcPtr DeferredTaskUPP;
  226. #endif
  227.  
  228. struct DeferredTask {
  229.     QElemPtr                        qLink;
  230.     short                            qType;
  231.     short                            dtFlags;
  232.     DeferredTaskUPP                    dtAddr;
  233.     long                            dtParam;
  234.     long                            dtReserved;
  235. };
  236. typedef struct DeferredTask DeferredTask, *DeferredTaskPtr;
  237.  
  238. struct SysEnvRec {
  239.     short                            environsVersion;
  240.     short                            machineType;
  241.     short                            systemVersion;
  242.     short                            processor;
  243.     Boolean                            hasFPU;
  244.     Boolean                            hasColorQD;
  245.     short                            keyBoardType;
  246.     short                            atDrvrVersNum;
  247.     short                            sysVRefNum;
  248. };
  249. typedef struct SysEnvRec SysEnvRec;
  250.  
  251. struct MachineLocation {
  252.     Fract                            latitude;
  253.     Fract                            longitude;
  254.     union {
  255.         SInt8                            dlsDelta;                /*signed byte; daylight savings delta*/
  256.         long                            gmtDelta;                /*must mask - see documentation*/
  257.     } u;
  258. };
  259.  
  260. typedef struct MachineLocation MachineLocation;
  261.  
  262. struct DateTimeRec {
  263.     short                            year;
  264.     short                            month;
  265.     short                            day;
  266.     short                            hour;
  267.     short                            minute;
  268.     short                            second;
  269.     short                            dayOfWeek;
  270. };
  271. typedef struct DateTimeRec DateTimeRec;
  272.  
  273. typedef wide LongDateTime;
  274.  
  275. union LongDateCvt {
  276.     wide                            c;
  277.     struct {
  278.         UInt32                            lHigh;
  279.         UInt32                            lLow;
  280.     }                                hl;
  281. };
  282. typedef union LongDateCvt LongDateCvt;
  283.  
  284. union LongDateRec {
  285.     struct {
  286.         short                            era;
  287.         short                            year;
  288.         short                            month;
  289.         short                            day;
  290.         short                            hour;
  291.         short                            minute;
  292.         short                            second;
  293.         short                            dayOfWeek;
  294.         short                            dayOfYear;
  295.         short                            weekOfYear;
  296.         short                            pm;
  297.         short                            res1;
  298.         short                            res2;
  299.         short                            res3;
  300.     }                                ld;
  301.     short                            list[14];                    /*Index by LongDateField!*/
  302.     struct {
  303.         short                            eraAlt;
  304.         DateTimeRec                        oldDate;
  305.     }                                od;
  306. };
  307. typedef union LongDateRec LongDateRec;
  308.  
  309. typedef SInt8 DateDelta;
  310.  
  311. struct TogglePB {
  312.     long                            togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  313.     ResType                            amChars;                    /*from 'itl0', but uppercased*/
  314.     ResType                            pmChars;                    /*from 'itl0', but uppercased*/
  315.     long                            reserved[4];
  316. };
  317. typedef struct TogglePB TogglePB;
  318.  
  319. typedef short ToggleResults;
  320.  
  321. enum {
  322.     uppDeferredTaskProcInfo = kRegisterBased
  323.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterA1, SIZE_CODE(sizeof(long)))
  324. };
  325.  
  326. #if GENERATINGCFM
  327. #define NewDeferredTaskProc(userRoutine)        \
  328.         (DeferredTaskUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDeferredTaskProcInfo, GetCurrentArchitecture())
  329. #else
  330. #define NewDeferredTaskProc(userRoutine)        \
  331.         ((DeferredTaskUPP) (userRoutine))
  332. #endif
  333.  
  334. #if GENERATINGCFM
  335. #define CallDeferredTaskProc(userRoutine, dtParam)        \
  336.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppDeferredTaskProcInfo, (dtParam))
  337. #else
  338. /* (*DeferredTaskProcPtr) cannot be called from a high-level language without the Mixed Mode Manager */
  339. #endif
  340.  
  341. extern pascal void LongDateToSeconds(const LongDateRec *lDate, LongDateTime *lSecs)
  342.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  343. extern pascal void LongSecondsToDate(LongDateTime *lSecs, LongDateRec *lDate)
  344.  FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  345. extern pascal ToggleResults ToggleDate(LongDateTime *lSecs, LongDateField field, DateDelta delta, short ch, const TogglePB *params)
  346.  FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  347. extern pascal short ValidDate(const LongDateRec *vDate, long flags, LongDateTime *newSecs)
  348.  FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  349. extern pascal Boolean IsMetric(void)
  350.  THREEWORDINLINE(0x3F3C, 0x0004, 0xA9ED);
  351. extern pascal SysPPtr GetSysPPtr(void)
  352.  THREEWORDINLINE(0x2EBC, 0x0000, 0x01F8);
  353.  
  354. #if !GENERATINGCFM
  355. #pragma parameter __D0 ReadDateTime(__A0)
  356. #endif
  357. extern pascal OSErr ReadDateTime(unsigned long *time)
  358.  ONEWORDINLINE(0xA039);
  359.  
  360. #if !GENERATINGCFM
  361. #pragma parameter GetDateTime(__A0)
  362. #endif
  363. extern pascal void GetDateTime(unsigned long *secs)
  364.  TWOWORDINLINE(0x20B8, 0x020C);
  365.  
  366. #if !GENERATINGCFM
  367. #pragma parameter __D0 SetDateTime(__D0)
  368. #endif
  369. extern pascal OSErr SetDateTime(unsigned long time)
  370.  ONEWORDINLINE(0xA03A);
  371.  
  372. #if !GENERATINGCFM
  373. #pragma parameter SetTime(__A0)
  374. #endif
  375. extern pascal void SetTime(const DateTimeRec *d)
  376.  TWOWORDINLINE(0xA9C7, 0xA03A);
  377.  
  378. #if !GENERATINGCFM
  379. #pragma parameter GetTime(__A0)
  380. #endif
  381. extern pascal void GetTime(DateTimeRec *d)
  382.  THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  383. extern pascal void DateToSeconds(const DateTimeRec *d, unsigned long *secs);
  384.  
  385. #if !GENERATINGCFM
  386. #pragma parameter SecondsToDate(__D0, __A0)
  387. #endif
  388. extern pascal void SecondsToDate(unsigned long secs, DateTimeRec *d)
  389.  ONEWORDINLINE(0xA9C6);
  390. extern pascal void SysBeep(short duration)
  391.  ONEWORDINLINE(0xA9C8);
  392.  
  393. #if !GENERATINGCFM
  394. #pragma parameter __D0 DTInstall(__A0)
  395. #endif
  396. extern pascal OSErr DTInstall(DeferredTaskPtr dtTaskPtr)
  397.  ONEWORDINLINE(0xA082);
  398. #if GENERATINGPOWERPC
  399. #define GetMMUMode() ((char)true32b)
  400. #define SwapMMUMode(x) (*(SInt8*)(x) = true32b)
  401. #else
  402. extern pascal SInt8 GetMMUMode( void )
  403.     TWOWORDINLINE( 0x1EB8, 0x0CB2 ); /* MOVE.b $0CB2,(SP) */
  404.  
  405. #if !GENERATINGCFM
  406. #pragma parameter SwapMMUMode(__A0)
  407. #endif
  408. extern pascal void SwapMMUMode(SInt8 *mode)
  409.  THREEWORDINLINE(0x1010, 0xA05D, 0x1080);
  410. #endif
  411. #if SystemSixOrLater
  412.  
  413. #if !GENERATINGCFM
  414. #pragma parameter __D0 SysEnvirons(__D0, __A0)
  415. #endif
  416. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld)
  417.  ONEWORDINLINE(0xA090);
  418. #else
  419. extern pascal OSErr SysEnvirons(short versionRequested, SysEnvRec *theWorld);
  420. #endif
  421.  
  422. #if !GENERATINGCFM
  423. #pragma parameter Delay(__A0, __A1)
  424. #endif
  425. extern pascal void Delay(long numTicks, long *finalTicks)
  426.  TWOWORDINLINE(0xA03B, 0x2280);
  427. /*
  428.     GetTrapAddress and SetTrapAddress are obsolete and should not
  429.     be used. Always use NGetTrapAddress and NSetTrapAddress instead.
  430.     The old routines will not be supported for PowerPC apps.
  431. */
  432. #if OLDROUTINENAMES && !GENERATINGCFM
  433.  
  434. #if !GENERATINGCFM
  435. #pragma parameter __A0 GetTrapAddress(__D0)
  436. #endif
  437. extern pascal UniversalProcPtr GetTrapAddress(short trapNum)
  438.  ONEWORDINLINE(0xA146);
  439.  
  440. #if !GENERATINGCFM
  441. #pragma parameter SetTrapAddress(__A0, __D0)
  442. #endif
  443. extern pascal void SetTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  444.  ONEWORDINLINE(0xA047);
  445. #endif
  446. extern pascal UniversalProcPtr NGetTrapAddress(short trapNum, TrapType tTyp);
  447. extern pascal void NSetTrapAddress(UniversalProcPtr trapAddr, short trapNum, TrapType tTyp);
  448.  
  449. #if !GENERATINGCFM
  450. #pragma parameter __A0 GetOSTrapAddress(__D0)
  451. #endif
  452. extern pascal UniversalProcPtr GetOSTrapAddress(short trapNum)
  453.  ONEWORDINLINE(0xA346);
  454.  
  455. #if !GENERATINGCFM
  456. #pragma parameter SetOSTrapAddress(__A0, __D0)
  457. #endif
  458. extern pascal void SetOSTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  459.  ONEWORDINLINE(0xA247);
  460.  
  461. #if !GENERATINGCFM
  462. #pragma parameter __A0 GetToolTrapAddress(__D0)
  463. #endif
  464. extern pascal UniversalProcPtr GetToolTrapAddress(short trapNum)
  465.  ONEWORDINLINE(0xA746);
  466.  
  467. #if !GENERATINGCFM
  468. #pragma parameter SetToolTrapAddress(__A0, __D0)
  469. #endif
  470. extern pascal void SetToolTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  471.  ONEWORDINLINE(0xA647);
  472.  
  473. #if !GENERATINGCFM
  474. #pragma parameter __A0 GetToolboxTrapAddress(__D0)
  475. #endif
  476. extern pascal UniversalProcPtr GetToolboxTrapAddress(short trapNum)
  477.  ONEWORDINLINE(0xA746);
  478.  
  479. #if !GENERATINGCFM
  480. #pragma parameter SetToolboxTrapAddress(__A0, __D0)
  481. #endif
  482. extern pascal void SetToolboxTrapAddress(UniversalProcPtr trapAddr, short trapNum)
  483.  ONEWORDINLINE(0xA647);
  484. extern pascal OSErr WriteParam(void);
  485.  
  486. #if !GENERATINGCFM
  487. #pragma parameter Enqueue(__A0, __A1)
  488. #endif
  489. extern pascal void Enqueue(QElemPtr qElement, QHdrPtr qHeader)
  490.  ONEWORDINLINE(0xA96F);
  491.  
  492. #if !GENERATINGCFM
  493. #pragma parameter __D0 Dequeue(__A0, __A1)
  494. #endif
  495. extern pascal OSErr Dequeue(QElemPtr qElement, QHdrPtr qHeader)
  496.  ONEWORDINLINE(0xA96E);
  497. extern long SetCurrentA5(void)
  498.  THREEWORDINLINE(0x200D, 0x2A78, 0x0904);
  499.  
  500. #if !GENERATINGCFM
  501. #pragma parameter __D0 SetA5(__D0)
  502. #endif
  503. extern long SetA5(long newA5)
  504.  ONEWORDINLINE(0xC18D);
  505. #if !SystemSevenOrLater
  506. extern pascal void Environs(short *rom, short *machine);
  507. #endif
  508.  
  509. #if !GENERATINGCFM
  510. #pragma parameter __D0 InitUtil
  511. #endif
  512. extern pascal OSErr InitUtil(void)
  513.  ONEWORDINLINE(0xA03F);
  514. #if GENERATING68K
  515. extern pascal Boolean SwapInstructionCache(Boolean cacheEnable);
  516. extern pascal void FlushInstructionCache(void)
  517.  TWOWORDINLINE(0x7001, 0xA098);
  518. extern pascal Boolean SwapDataCache(Boolean cacheEnable);
  519. extern pascal void FlushDataCache(void)
  520.  TWOWORDINLINE(0x7003, 0xA098);
  521. extern pascal void FlushCodeCache(void)
  522.  ONEWORDINLINE(0xA0BD);
  523.  
  524. #if !GENERATINGCFM
  525. #pragma parameter FlushCodeCacheRange(__A0, __A1)
  526. #endif
  527. extern pascal void FlushCodeCacheRange(void *address, unsigned long count)
  528.  TWOWORDINLINE(0x7009, 0xA098);
  529. #endif
  530.  
  531. #if !GENERATINGCFM
  532. #pragma parameter ReadLocation(__A0)
  533. #endif
  534. extern pascal void ReadLocation(MachineLocation *loc)
  535.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA051);
  536.  
  537. #if !GENERATINGCFM
  538. #pragma parameter WriteLocation(__A0)
  539. #endif
  540. extern pascal void WriteLocation(const MachineLocation *loc)
  541.  FOURWORDINLINE(0x203C, 0x000C, 0x00E4, 0xA052);
  542. #if GENERATINGPOWERPC
  543. extern pascal UniversalProcPtr *GetTrapVector(short trapNumber);
  544. #endif
  545. #if OLDROUTINENAMES
  546. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  547. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  548. #define IUMetric() IsMetric()
  549. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  550. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  551. #endif
  552.  
  553. #if PRAGMA_IMPORT_SUPPORTED
  554. #pragma import off
  555. #endif
  556.  
  557. #if PRAGMA_ALIGN_SUPPORTED
  558. #pragma options align=reset
  559. #endif
  560.  
  561. #ifdef __cplusplus
  562. }
  563. #endif
  564.  
  565. #endif /* __OSUTILS__ */
  566.